﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};

	var auditData = Jxstar.findComboData('audit');
	var applystatusData = Jxstar.findComboData('applystatus');
	var authtypeData = Jxstar.findComboData('authtype');
	var moneytypeData = Jxstar.findComboData('moneytype');
	var purtype2Data = Jxstar.findComboData('purtype2');
	var orgtypeData = Jxstar.findComboData('orgtype');

	var cols = [
	{col:{header:'记录状态', width:83, sortable:true, hidden:true, align:'center',
		renderer:function(value){
			for (var i = 0; i < auditData.length; i++) {
				if (auditData[i][0] == value)
					return auditData[i][1];
			}
		}}, field:{name:'pur_apply__auditing',type:'string'}},
	{col:{header:'采购单号', width:116, sortable:true}, field:{name:'pur_apply__apply_code',type:'string'}},
	{col:{header:'采购状态', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: applystatusData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: applystatusData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < applystatusData.length; i++) {
				if (applystatusData[i][0] == value)
					return applystatusData[i][1];
			}
		}}, field:{name:'pur_apply__apply_status',type:'string'}},
	{col:{header:'项目编号', width:100, sortable:true}, field:{name:'pur_apply__project_code',type:'string'}},
	{col:{header:'采购单名称', width:100, sortable:true}, field:{name:'pur_apply__apply_name',type:'string'}},
	{col:{header:'授权形式', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: authtypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: authtypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < authtypeData.length; i++) {
				if (authtypeData[i][0] == value)
					return authtypeData[i][1];
			}
		}}, field:{name:'pur_apply__auth_type',type:'string'}},
	{col:{header:'项目主要内容', width:200, sortable:true}, field:{name:'pur_apply__project_content',type:'string'}},
	{col:{header:'中标金额(万元)', width:100, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'pur_apply__bid_money',type:'float'}},
	{col:{header:'选中供应商', width:100, sortable:true}, field:{name:'pur_apply__provider_name',type:'string'}},
	{col:{header:'项目类别', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: moneytypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: moneytypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < moneytypeData.length; i++) {
				if (moneytypeData[i][0] == value)
					return moneytypeData[i][1];
			}
		}}, field:{name:'pur_apply__money_type',type:'string'}},
	{col:{header:'投资计划编号', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__plan_code',type:'string'}},
	{col:{header:'预算金额(万元)', width:100, sortable:true, renderer:JxUtil.formatNumber(6)}, field:{name:'pur_apply__project_money',type:'float'}},
	{col:{header:'实施单位', width:100, sortable:true}, field:{name:'pur_apply__dept_name',type:'string'}},
	{col:{header:'项目负责人', width:100, sortable:true}, field:{name:'pur_apply__project_user',type:'string'}},
	{col:{header:'采购方式', width:100, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: purtype2Data
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: purtype2Data[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < purtype2Data.length; i++) {
				if (purtype2Data[i][0] == value)
					return purtype2Data[i][1];
			}
		}}, field:{name:'pur_apply__pur_type',type:'string'}},
	{col:{header:'申请人', width:79, sortable:true}, field:{name:'pur_apply__apply_user',type:'string'}},
	{col:{header:'申请日期', width:100, sortable:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'pur_apply__apply_date',type:'date'}},
	{col:{header:'项目名称', width:244, sortable:true}, field:{name:'pur_apply__project_name',type:'string'}},
	{col:{header:'组织形式', width:100, sortable:true, hidden:true, align:'center',
		renderer:function(value){
			for (var i = 0; i < orgtypeData.length; i++) {
				if (orgtypeData[i][0] == value)
					return orgtypeData[i][1];
			}
		}}, field:{name:'pur_apply__org_type',type:'string'}},
	{col:{header:'代理机构名称', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__proxy_org',type:'string'}},
	{col:{header:'采购内容', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__pur_content',type:'string'}},
	{col:{header:'申请理由', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__pur_cause',type:'string'}},
	{col:{header:'备注', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__pur_memo',type:'string'}},
	{col:{header:'项目负责人ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__project_userid',type:'string'}},
	{col:{header:'投资计划ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__plan_id',type:'string'}},
	{col:{header:'联系人ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__apply_userid',type:'string'}},
	{col:{header:'主键', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__apply_id',type:'string'}},
	{col:{header:'实施单位ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__dept_id',type:'string'}},
	{col:{header:'项目ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__project_id',type:'string'}},
	{col:{header:'项目批复文号', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__check_fileno',type:'string'}},
	{col:{header:'项目批复名称', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__check_name',type:'string'}},
	{col:{header:'主管部门', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__done_deptname',type:'string'}},
	{col:{header:'选中供应商ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__provider_id',type:'string'}},
	{col:{header:'主管部门ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__done_deptid',type:'string'}},
	{col:{header:'中标日期', width:100, sortable:true, hidden:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'pur_apply__bid_date',type:'date'}},
	{col:{header:'采购单方案申请ID', width:100, sortable:true, hidden:true}, field:{name:'pur_apply__check_id',type:'string'}}
	];
	
	config.param = {
		cols: cols,
		sorts: null,
		hasQuery: '1',
		isedit: '0',
		isshow: '1',
		funid: 'pur_apply'
	};
	
	config.eventcfg = {				//已招标公告		tenderpub: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selected(records)) return;						var self = this;			//取选择记录的主键值			var params = 'funid='+ self.define.nodeid;			for (var i = 0; i < records.length; i++) {				params += '&keyid=' + records[i].get(self.define.pkcol);			}			//设置请求的参数			params += '&pagetype=grid&eventcode=tenderpub';						//执行处理的内容			var endcall = function(data) {				//重新加载数据				self.grid.getStore().reload();			};			//发送请求			Request.postRequest(params, endcall);		},				//已发售标书		tendersale: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selected(records)) return;						var self = this;			//取选择记录的主键值			var params = 'funid='+ self.define.nodeid;			for (var i = 0; i < records.length; i++) {				params += '&keyid=' + records[i].get(self.define.pkcol);			}						//设置请求的参数			params += '&pagetype=grid&eventcode=tendersale';			//执行处理的内容			var endcall = function(data) {				//重新加载数据				self.grid.getStore().reload();			};			//发送请求			Request.postRequest(params, endcall);		},		//标书发售		filesale:function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selected(records)) return;						var self = this;			//取选择记录的主键值			var params = 'funid='+ self.define.nodeid;			for (var i = 0; i < records.length; i++) {				params += '&keyid=' + records[i].get(self.define.pkcol);			}						//设置请求的参数			params += '&pagetype=subeditgrid&eventcode=filesale';			//执行处理的内容			var endcall = function(data) {				//重新加载数据				self.grid.getStore().reload();			};			//发送请求			Request.postRequest(params, endcall);		},				query_chk: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selectone(records)) return;			var selfunid = records[0].get('pur_apply__apply_id');			var selfunid2 = records[0].get('pur_apply__check_id');			if(selfunid2 == '') {				JxHint.alert('该采购单没有对应的采购方案申请！');					return false;			};						//加载Form数据			var hdcall = function(page) {				//设置外键键				//page.getForm().fkName = 'pur_apply_chk__apply_id';				//page.getForm().fkValue = selfunid;								//加载显示数据				var options = {					where_sql: 'pur_apply_chk.apply_chkid = ?',					where_type: 'string',					where_value: selfunid2,					callback: function(data) {						//如果没有数据则执行新增						if (data.length == 0) {							//page.formNode.event.create();						} else {							var r = page.formNode.event.newRecord(data[0]);														page.getForm().myRecord = r;							page.getForm().loadRecord(r);						}					}				};				Jxstar.queryData('pur_apply_chk', options);			};						//显示数据			var define = Jxstar.findNode('pur_apply_chk');			Jxstar.showData({				filename: define.formpage,				title: define.nodetitle,				pagetype:"query",				width: 750,				height: 400,				callback: hdcall			});		},		query_file: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selectone(records)) return;			var selfunid = records[0].get('pur_apply__apply_id');						//加载Form数据			var hdcall = function(page) {				//设置外键键				page.getForm().fkName = 'pur_apply_file__apply_id';				page.getForm().fkValue = selfunid;								//加载显示数据				var options = {					where_sql: 'pur_apply_file.apply_id = ?',					where_type: 'string',					where_value: selfunid,					callback: function(data) {						//如果没有数据则执行新增						if (data.length == 0) {							//page.formNode.event.create();						} else {							var r = page.formNode.event.newRecord(data[0]);														page.getForm().myRecord = r;							page.getForm().loadRecord(r);						}					}				};				Jxstar.queryData('pur_apply_file', options);			};						//显示数据			var define = Jxstar.findNode('pur_apply_file');			Jxstar.showData({				filename: define.formpage,				title: define.nodetitle,				pagetype:"query",				width: 750,				height: 400,				callback: hdcall			});		},				query_audit: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selectone(records)) return;			var selfunid = records[0].get('pur_apply__apply_id');						//加载Form数据			var hdcall = function(page) {				//设置外键键				page.getForm().fkName = 'pur_apply_audit__apply_id';				page.getForm().fkValue = selfunid;								//加载显示数据				var options = {					where_sql: 'pur_apply_audit.apply_id = ?',					where_type: 'string',					where_value: selfunid,					callback: function(data) {						//如果没有数据则执行新增						if (data.length == 0) {							//page.formNode.event.create();						} else {							var r = page.formNode.event.newRecord(data[0]);														page.getForm().myRecord = r;							page.getForm().loadRecord(r);						}					}				};				Jxstar.queryData('pur_apply_audit', options);			};						//显示数据			var define = Jxstar.findNode('pur_apply_audit');			Jxstar.showData({				filename: define.formpage,				title: define.nodetitle,				pagetype:"query",				width: 750,				height: 400,				callback: hdcall			});		},				query_bid: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selectone(records)) return;			var selfunid = records[0].get('pur_apply__apply_id');						//加载Form数据			var hdcall = function(page) {				//设置外键键				page.getForm().fkName = 'pur_apply_bid__apply_id';				page.getForm().fkValue = selfunid;								//加载显示数据				var options = {					where_sql: 'pur_apply_bid.apply_id = ?',					where_type: 'string',					where_value: selfunid,					callback: function(data) {						//如果没有数据则执行新增						if (data.length == 0) {							//page.formNode.event.create();						} else {							var r = page.formNode.event.newRecord(data[0]);														page.getForm().myRecord = r;							page.getForm().loadRecord(r);						}					}				};				Jxstar.queryData('pur_apply_bid', options);			};						//显示数据			var define = Jxstar.findNode('pur_apply_bid');			Jxstar.showData({				filename: define.formpage,				title: define.nodetitle,				pagetype:"query",				width: 750,				height: 400,				callback: hdcall			});		}
};
		
	return new Jxstar.GridNode(config);
}